<template>
  <el-form ref="ruleForm" :model="formData" :rules="rules" label-width="100px" class="demo-ruleForm">
    <el-row>
      <el-col :span="12">
        <el-form-item label="日期" prop="gdate">
          <el-date-picker
            v-model="formData.gdate"
            type="date"
            placeholder="日期"
            value-format="yyyy-MM-dd"
          /></el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="平均温度" prop="temp_avg">
          <el-input v-model="formData.temp_avg" type="number" placeholder="平均温度">
            <template slot="append">℃</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="最低温度" prop="temp_low">
          <el-input v-model="formData.temp_low" type="number" placeholder="最低温度">
            <template slot="append">℃</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="最高温度" prop="temp_high">
          <el-input v-model="formData.temp_high" type="number" placeholder="最高温度">
            <template slot="append">℃</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="降雨量" prop="rainfall">
          <el-input v-model="formData.rainfall" type="number" placeholder="降雨量">
            <template slot="append">mm</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="风速" prop="wind_spd">
          <el-input v-model="formData.wind_spd" type="number" placeholder="风速">
            <template slot="append">m/s</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="太阳辐射" prop="radiation">
          <el-input v-model="formData.radiation" type="number" placeholder="太阳辐射">
            <template slot="append">MJ/m²d</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="相对湿度" prop="humidity">
          <el-input v-model="formData.humidity" type="number" placeholder="相对湿度">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="大气压" prop="pressure">
          <el-input v-model="formData.pressure" type="number" placeholder="大气压">
            <template slot="append">kPa</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="ET0" prop="et0">
          <el-input v-model="formData.et0" type="number" placeholder="ET0">
            <template slot="append">mm</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="积温" prop="temp_acc">
          <el-input v-model="formData.temp_acc" type="number" placeholder="积温">
            <template slot="append">℃</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="日照时长" prop="sunshine_acc">
          <el-input v-model="formData.sunshine_acc" type="number" placeholder="日照时长">
            <template slot="append">h</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item>
      <el-button type="primary" @click="submit('ruleForm')">提交</el-button>
      <el-button @click="reset('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  props: {
    formData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('submit', this.formData)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    reset(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
